from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver=webdriver.Firefox()
driver.get('http://10.59.9.13:7002/')
time.sleep(2)
print('--------------------------------')
print('前台')
print('--------------------------------')
# 点击登录，跳转到登录按钮
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 预期1
yq1=driver.find_element(By.CLASS_NAME,'reg-new').text
print(yq1)
# 输入用户名密码
driver.find_element(By.NAME,'username').send_keys('19525482253')
driver.find_element(By.NAME,'password').send_keys('040708')
time.sleep(5)
# 点击登录按钮
driver.find_element(By.CSS_SELECTOR,'.finish-btn').click()
time.sleep(2)
# 预期2 登录成功后跳转到会员中心
yq2=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').text
print(yq2)
# 点击首页
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 点击秒杀
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[4]/a').click()
time.sleep(2)
# 预期3
yq3=driver.find_element(By.XPATH,'/html/body/div[4]/a[2]').text
print(yq3)
# 选择商品
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[2]/div[1]/span/a/img').click()
time.sleep(2)
# 预期4
yq4=driver.find_element(By.XPATH,'/html/body/div[4]/a[3]').text
print(yq4)
# 预期5 商品的金额
yq5=driver.find_element(By.ID,'sell-price-box').text
print(yq5)
# 修改商品数量
xg=driver.find_element(By.XPATH,'//*[@id="store_nums"]')
xg.clear()
xg.send_keys(2)
time.sleep(2)
# 点击立即购买
driver.find_element(By.ID,'buy-cart').click()
time.sleep(2)
# 预期6 成功跳转到订单页面
yq6=driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
print(yq6)
# 选择地址
driver.find_element(By.ID,'address-13').click()
time.sleep(2)
# 现在支付方式
driver.find_element(By.XPATH,'/html/body/div[4]/form/div[3]/div[2]/div[1]/label/input').click()
time.sleep(2)

driver.execute_script('window.scrollTo(0,500)')
time.sleep(2)
# 预期7 商品金额
yq7=driver.find_element(By.XPATH,'//*[@id="real-amount"]').text
print(yq7)
assert float(yq7) == float(yq5) * 2
time.sleep(2)

# 预期8 运费
yq8=driver.find_element(By.ID,'real-freight').text
yq81=yq8.replace('+','')
print(float(yq81))
time.sleep(2)
# 预期9 商品总金额
yq9=driver.find_element(By.XPATH,'//*[@id="order-amount"]').text
print(yq9)
assert float(yq9) == float(yq7) + float(yq81)
time.sleep(2)
# 点击下一步
driver.find_element(By.ID,'order-button').click()
time.sleep(2)
# 预期10 订单完成
yq10=driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
print(yq10)
# 预期11 订单编号
yq11=driver.find_element(By.XPATH,'/html/body/div[4]/div[4]/div[2]/ul/li[1]').text
yq111=yq11.replace('订单编号：','')
print(yq111)
# 查看订单
driver.find_element(By.CLASS_NAME,'immediate-pay').click()
time.sleep(2)
# 预期12 我的订单
yq12 = driver.find_element(By.XPATH,'/html/body/div[4]/a[3]').text
print(yq12)
# 申请退款
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[6]/td[2]/div[1]/a').click()
time.sleep(2)
# 退款说明
driver.find_element(By.CLASS_NAME,'reason-text').send_keys('在其他平台找到了更具性价比的商品')
time.sleep(2)
# 提交退款说明
driver.find_element(By.ID,'user-info-btn').click()
time.sleep(2)


print('--------------------------------')
print('后台')
print('--------------------------------')
driver.get('http://10.59.9.13:7002/admin/login/index.html')
time.sleep(2)
# 输入用户名密码
driver.find_element(By.NAME,'username').send_keys('admin')
driver.find_element(By.NAME,'password').send_keys('admin888')
time.sleep(5)
# 点击登录按钮
driver.find_element(By.XPATH,'/html/body/div[2]/div/div/form/div[4]/button').click()
time.sleep(5)
# 点击订单
driver.find_element(By.XPATH,'/html/body/div/header/nav/div[1]/ul/li[4]/a').click()
time.sleep(2)
# 预期14
yq14=driver.find_element(By.XPATH,'/html/body/div/div/div[1]/div/ul/li[2]/a').text
print(yq14)
# 输入订单号
driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/form/div[2]/div[2]/div/input').send_keys(yq111)
time.sleep(2)
# 点击搜索
driver.find_element(By.XPATH,'//*[@id="search-btn"]').click()
time.sleep(5)
# 点击查看商品详情
driver.find_element(By.XPATH,'/html/body/div/div/section/div/div/div[2]/div[2]/table/tbody/tr[1]/td[8]/div/p[2]/a[1]').click()
time.sleep(2)
# 点击退款
driver.find_element(By.XPATH,'/html/body/div/div/section/div/form/div/div/div[1]/div[1]/div/a[3]').click()
time.sleep(2)
# 预期13
yq13=driver.find_element(By.XPATH,'/html/body/div/div/div/div/ul/li[2]/a').text
print(yq13)
# 说明情况
driver.find_element(By.XPATH,'/html/body/div/div/section/div/form/div/div[1]/div/div[2]/table/tbody/tr[10]/td/textarea').send_keys('未发货，可以退款')
time.sleep(2)
# 点击立即提交
driver.find_element(By.XPATH,'/html/body/div/div/section/div/form/div/div[2]/div/button[1]').click()
time.sleep(2)


print('--------------------------------')
print('返回前台')
print('--------------------------------')
driver.get('http://10.59.9.13:7002/')
time.sleep(2)
# 点击我的订单
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[4]/a').click()
time.sleep(2)
# 查看订单详情
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/table/tbody/tr[3]/td[3]/div[2]/a').click()
time.sleep(2)
# 退款成功
tk=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[5]/td[2]').text
print(tk)
driver.quit()

















